24. Verifying Hashed Cookies
Verifying Hashed Cookies
Question:
Start Quiz:
import hashlib
def hash_str(s):
return hashlib.md5(s).hexdigest()
def make_secure_val(s):
return "%s,%s" % (s, hash_str(s))
# -----------------
# User Instructions
#
# Implement the function check_secure_val, which takes a string of the format
# s,HASH
# and returns s if hash_str(s) == HASH, otherwise None
def check_secure_val(h):
###Your code here
User's Answer:
(Note: The answer done by the user is not guaranteed to be correct)
import hashlib
def hash_str(s):
return hashlib.md5(s).hexdigest()
def make_secure_val(s):
return "%s,%s" % (s, hash_str(s))
# -----------------
# User Instructions
#
# Implement the function check_secure_val, which takes a string of the format
# s,HASH
# and returns s if hash_str(s) == HASH, otherwise None
def check_secure_val(h):
test = h.split(",")
if hash_str(test[0])==test[1]:
return test[0]
print check_secure_val("abc,23")